package com.icxcc.listener;

import com.alibaba.fastjson.JSONObject;
import com.icxcc.constant.RabbitConstant;
import com.icxcc.service.RabbitMessageService;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

@Component
@RabbitListener(queues = RabbitConstant.DELAY_MESSAGE_QUEUE)
public class DelayMessageListener {
    @Autowired
    private RabbitMessageService rabbitMessageService;

    @RabbitHandler
    public void process(String message){
        //log.info(message);

        Map<String,String> map = JSONObject.parseObject(message, Map.class);
        rabbitMessageService.send(map.get("queueName"), map.get("message"));
    }
}
